#pragma once

#include "fxcc/yml/Serializer.h"
#include "e2d/core/Entity.h"

#define FXCC_YML_ENTITY_ENCODE_DECODE                                                           \
template<typename T>                                                                           \
bool EncodeEntity(YAML::Node& node, const e2d::Entity* entity)         \
{                                                                                              \
    if (entity->HasComponent<T>())                                                             \
    {                                                                                          \
        if (entity->GetConst<T>().m_Exist)                                                     \
            SetVariable<T>(node, T::_Label_(), entity->GetConst<T>());                                  \
    }                                                                                          \
    return entity->HasComponent<T>();                                                          \
}                                                                                              \
                                                                                               \
template<typename T>                                                                           \
bool DecodeEntity(const YAML::Node& node, e2d::Entity* entity)         \
{                                                                                              \
    bool hasFlag = node[T::_Label_()].IsDefined();                                                      \
    if (hasFlag)                                                                               \
    {                                                                                          \
        return GetVariable<T>(node, T::_Label_(), entity->GetOrEmplace<T>());                           \
    }                                                                                          \
                                                                                               \
    return false;                                                                              \
}                                                                                              

namespace e2d
{
    struct Entity;

    using BasicSerializer = fxcc::yml::Serializer;

};